class Admin::PostsController < ApplicationController
	before_filter :login_required
	before_filter :find_post, :only=>[:edit, :update, :destroy]
	
	def index
		@posts = Post.paginate(:page=>params[:page], :per_page=>20, :order=>"created_at DESC")
	end
	
	def new
		@post = Post.new
	end
	
	def create
		@post = current_user.posts.new(params[:post])
		@post.save!
		redirect_to admin_posts_path
		rescue ActiveRecord::RecordInvalid
    	render :action => 'new'
	end
	
	def edit
	end
	
	def update
		@post.update_attributes!(params[:post])
		redirect_to admin_posts_path
		rescue ActiveRecord::RecordInvalid
    	render :action => 'edit'
	end
	
	def destroy
		@post.destroy
		redirect_to admin_posts_path
	end
	
	private
	
	def find_post
		@post = Post.find(params[:id])
	end
end
